package com.fengzheng.basic.common.config.response.exception;

import com.fengzheng.basic.common.config.response.HttpCode;
import com.fengzheng.basic.common.config.response.ResultCodeMsg;
import lombok.Data;

/**
 * 自定义运行时异常
 * @author HU
 * @date 2022/1/21 10:01
 */
@Data
public class ServiceException extends RuntimeException{

    private Integer code;
    private Integer httpCode;

    public final static Integer DEFAULT_CODE = 0;

    public ServiceException(int code, int httpCode ,String msg){
        super(msg);
        this.code = code;
        this.httpCode = httpCode;
    }

    public ServiceException(String message){
        this(DEFAULT_CODE, HttpCode.DEFAULT_HTTP_CODE.httpCode, message);
    }

    public ServiceException(ResultCodeMsg resultCodeMsg){
        super(resultCodeMsg.msg);
        this.code = resultCodeMsg.code;
        this.httpCode = resultCodeMsg.httpCode;
    }

}
